package com.xpalive.user.controller;

import com.xpalive.base.dto.page.PageReq;
import com.xpalive.base.dto.page.PageRsp;
import com.xpalive.config.spring.Respbody.RespResultWrap;
import com.xpalive.user.dto.UserQuery;
import com.xpalive.user.model.User;
import com.xpalive.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RespResultWrap
@RequestMapping("/user")
@Api(
    tags = {"user"}
)
@AllArgsConstructor
public class UserController {

    private UserService userService;

    @PostMapping("/editUser")
    @ApiOperation("保存用户")
    public User editUser(@RequestBody @Valid User user) {
        userService.saveOrUpdate(user);
        return user;
    }

    @GetMapping("/findPage")
    @ApiOperation("分页查询用户")
    public PageRsp<User> findPage(PageReq pageReq, UserQuery userQuery) {
        return userService.list(pageReq, userQuery);
    }

    @GetMapping("/findById")
    @ApiOperation("查询用户")
    public User findById(@RequestParam Long id) {
        return userService.getById(id);
    }


    @GetMapping("/testReqWrap")
    @ApiOperation("查询姓名")
    public String testLoginId(@RequestParam(required = false) Long loginUserId) {
        return "false" + loginUserId;
    }

}
